package com.douyu.data.up.controller;

import com.douyu.data.common.CommonMessage;
import com.douyu.data.common.Resources;
import com.douyu.data.common.Result;
import com.douyu.data.up.api.UpApi;
import com.douyu.data.up.model.UpListModel;
import com.douyu.data.up.model.UpModel;
import com.douyu.data.up.service.UpService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.configurationprocessor.json.JSONException;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
public class UpController implements UpApi {
    //调试日志
    private final static Logger logger = LoggerFactory.getLogger(UpController.class);


    @Autowired
    private UpService upServiceImpl;

    @Override
    public Result<UpModel> getUpData(String id) {
        Result<UpModel> upDetail = upServiceImpl.getUpDetail(id);
        return upDetail;
    }

    @Override
    public Result<String> addUp(String id) throws IOException, JSONException {
        logger.info("添加主播开始");
        Result<String> result = upServiceImpl.addUp(id);
        logger.info("添加主播结束");
        return result;
    }

    @Override
    public Result<UpListModel> getUpList(@RequestParam String id,
                                         @RequestParam String name,
                                         @RequestParam String levelFrom,
                                         @RequestParam String levelTo,
                                         @RequestParam String association,
                                         @RequestParam String online,
                                         @RequestParam String attentionFrom,
                                         @RequestParam String attentionTo,
                                         @RequestParam String vipNumberFrom,
                                         @RequestParam String vipNumberTo,
                                         @RequestParam String diamondFansFrom,
                                         @RequestParam String diamondFansTo,
                                         @RequestParam Integer pageSize,
                                         @RequestParam Integer pageNum) {
        logger.info("获取主播一览开始");
        Result<UpListModel> result = new Result<>();
        UpListModel upList = upServiceImpl.getUpList(id, name, levelFrom, levelTo, association, online, attentionFrom, attentionTo, vipNumberFrom, vipNumberTo, diamondFansFrom, diamondFansTo, pageSize, pageNum);
        if(upList == null){
            return result.ng(Resources.getProperty(CommonMessage.E00002));
        }
        result.setResult(upList);
        logger.info("获取主播一览结束");
        return result.ok();
    }

}
